package GinRouter

import "github.com/gin-gonic/gin"

type BaseRouter struct {
	GinEngine *gin.Engine
	Path string
	router *gin.Engine
}

func (instance *BaseRouter) SetRouter(router *gin.Engine) {
	instance.router = router
}

func (instance BaseRouter) GetEngine() *gin.Engine {
	return instance.GinEngine
}

func (instance BaseRouter) InitRouter() {
	instance.router = instance.GinEngine
}

func (instance BaseRouter) Get(relativePath string, respCallback RespCallback) {
	instance.router.GET(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}

func (instance BaseRouter) Post(relativePath string, respCallback RespCallback) {
	instance.router.POST(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}

func (instance BaseRouter) Put(relativePath string, respCallback RespCallback) {
	instance.router.PUT(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}

func (instance BaseRouter) Delete(relativePath string, respCallback RespCallback) {
	instance.router.DELETE(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}
